<?php

use Jialeo\LaravelSchemaExtend\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUserLoanRequestsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('user_loan_requests', function (Blueprint $table) {
            $table->charset = 'utf8';
            $table->collation = 'utf8_general_ci';
            $table->comment = '用户借款申请授信表';
            $table->increments('id');
            $table->unsignedInteger('user_id')->comment('用户id')->index();
            $table->unsignedInteger('loan_money')->default(0)->comment('借款金额 单位分');
            $table->unsignedTinyInteger('period')->default(0)->comment('借款周期');
            $table->string('use')->default('')->comment('用途');
            $table->unsignedInteger('cert_ocr_id')->default(0)->comment('用户身份证信息id');
            $table->unsignedInteger('cash_card_choice_id')->default(0)->comment('用户储蓄卡id');
            $table->unsignedInteger('credit_card_choice_id')->default(0)->comment('用户信用卡id');
            $table->unsignedInteger('user_face_log_id')->default(0)->comment('用户face++验证id');
            $table->unsignedInteger('user_base_info_id')->default(0)->comment('用户基础信息id');
            $table->unsignedInteger('user_phone_service_id')->default(0)->comment('用户手机认证id');
            $table->unsignedInteger('zhima_id')->default(0)->comment('用户芝麻信用认证id');
            $table->timestamp('apply_time')->nullable()->comment('申请授信时间');
            $table->timestamp('failed_time')->nullable()->comment('申请授信失败时间');
            $table->string('credit_id')->nullable()->comment('授信id')->unique();
            $table->timestamp('credit_time')->nullable()->comment('授信成功时间');
            $table->unsignedTinyInteger('actually_period')->default(0)->comment('实际期数');
            $table->unsignedInteger('actually_loan_money')->default(0)->comment('实际金额');
            $table->string('channel')->default('')->comment('渠道号');
            $table->string('trans_id')->comment('借款申请流水号');
            $table->unsignedInteger('change_card_choice_id')->default(0)->comment('用户换卡记录id');
            $table->unsignedInteger('pre_insurance_amt')->default(0)->comment('前置险金额');
            $table->string('failed_reason')->nullable()->comment('授信失败原因');
            $table->unsignedTinyInteger('current')->default(1)->comment('用户当前的授信记录');
            $table->tinyInteger('status')->default(1)->comment('审核状态：0未完成 1待申请 2申请中 3申请成功 4申请失败 5超时 6完全超时 7风控失败 8风控拒绝 9等待风控 10缺少信息');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('user_loan_requests');
    }
}
